var users = null;
var configs = null;
var config = null;
var m_GH;

const url_planInfo = "https://www.xdfznh.club/wxpadbe/execute/query/华宇印染/select * from plan where vatNum='{{vatNum}}'";

function getCurPageUrl(){
	return window.location.href;
}

function reqConfigs(){// 请求后端配置对象构成的数组
	let that = this;
	const url_configs = 'https://www.xdfznh.club/wxpadbe/wx/getWxJsApiConfigs/' + getCurPageUrl() ;	
	$.ajax({
		type : "GET",
		contentType: "application/json;charset=UTF-8",
		url : url_configs,
		success : function(res){// 返回的数据是配置对象构成的数组，取下标2
			that.configs = res.data;// 全局保存配置对象数组
			that.config = res.data[2];
			that.applyConfigs(res.data[2]);
		},
		error : function(e){//请求失败，包含具体的错误信息
			alert(e.status + ':' + e.responseText);
	}})
}

function applyConfigs(conf){
	let self = this;
	 wx.config({
		debug:false,
		appId:conf.appId,
		timestamp:conf.timestamp,
		nonceStr:conf.nonceStr,
		signature:conf.signature,
		jsApiList:['checkJsApi','scanQRCode']
    });
	
	wx.ready(function(){
		self.wxScan();
	})
}

function wxScan(){// 调用扫一扫
	let that = this;
	wx.scanQRCode({
		needResult: 1,
        scanType: ["qrCode","barCode"],
        success: function(res){
			let vatnum = that.getVatnum(res);
			//that.getPlanInfo(vatnum);
			m_GH=vatnum;
			getData();
		}
	});
}

// 扫描后返回的结果处理后返回缸号
function getVatnum(data){
	if( data.length <=0 ) return '';
	let arr = data.resultStr.split(",");
	return arr[1];
}

function getPlanInfo(vatnum){
	const url = url_planInfo.replace('{{vatNum}}',vatnum);
	$.ajax({
		type : "GET",
		contentType: "application/json;charset=UTF-8",
		url : url,
		success : function(res){// 返回的数据是配置对象构成的数组，取下标2
			//alert('请求来的缸单信息是：' + JSON.stringify(res));
		},
		error : function(e){//请求失败，包含具体的错误信息
			alert(e.status + ':' + e.responseText);
	}})
}